//
//  HTSysLogin.m
//  HTERPManApp
//
//  Created by standychen on 14-11-10.
//  Copyright (c) 2014年 HT. All rights reserved.
//

#import "HTSysLogin.h"
#import "HTFrameKit.h"
#import "HTSysKit.h"
#import "ASIFormDataRequest.h"
#import "AppDelegate.h"

//系统登陆控制类
@implementation HTSysLogin

//异步调用登录验证，不应使用
+(void)hmLoginActionWithComany:(NSString *)company andUserName:(NSString *)username andPassword:(NSString *)password complete:(void(^)())blocksuccess
{
    HTFrameNet *htnet=[[HTFrameNet alloc] init];
    
    
    NSDictionary *dict = @{ @"ptvid":company,@"ptuid":username,@"ptupassword":password};
    [htnet hmNetWCFmethodName:@"srvlogin/CheckLogin" andDic:dict complete:^(NSString *backstr)
     {
         NSDictionary *rootDict=[HTFrameNet hmConvertDictFromJsonStr:backstr];
         NSDictionary *resultDict=[rootDict objectForKey:kpNET_RETURN_ENTITY_DATA];
         //NSString *flag2=[resultDict objectForKey:@"flagstr"];
         NSString *flag=[resultDict objectForKey:@"flag"];
         long flagInt = [flag integerValue];
         if(flagInt == 1)//登陆通过
         {
             //此处开始填写通用的赋值系统登录方法等
             
             //[HTSysParam loginUseridSet:username];
             [HTSysParam loadParamWithLoginAction:resultDict];
             //跳转到主页面  改成执行代码块
             //[self performSegueWithIdentifier:@"loginsegue" sender:nil];
             blocksuccess();
         }
         else
         {
             NSString *info=[resultDict objectForKey:@"info"];
             
             [HTFrameAlert hmAlertInfo:info];//提示信息
         }
         
         
     }];

}



//登录校验asi
+(void)hmCheckLogin_ASI:(NSString *)company andUserName:(NSString *)username andPassword:(NSString *)password complete:(void(^)())blocksuccess finally:(void(^)())blockfinally
{
   
    
    
    HTFrameNet *htnet=[[HTFrameNet alloc] init];
    NSString *methodname=[[NSString alloc] initWithFormat:@"%@/%@/%@/%@",@"srvlogin/CheckLoginGet",company,username,password];
    [htnet hmNetASImethodName:methodname complete:^(NSString *backstr) {
        
        NSDictionary *rootDict=[HTFrameNet hmConvertDictFromJsonStr:backstr];
        NSDictionary *resultDict=[rootDict objectForKey:kpNET_RETURN_ENTITY_DATA];
        NSString *flag=[resultDict objectForKey:@"flag"];
        NSString *version=[resultDict objectForKey:@"version"];
        
        long flagInt = [flag integerValue];
        if(flagInt == 1)//登陆通过
        {
            AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
            myDelegate.backVersion=version;
            
            //此处开始填写通用的赋值系统登录方法等
            [HTSysParam loadParamWithLoginAction:resultDict];
             //改成执行代码块
             blocksuccess();
            
                       
        }
        else
        {
            NSString *info=[resultDict objectForKey:@"info"];
            if([info isEqualToString:@""]){
                info=@"请输入密码！";
            }
            
            [HTFrameAlert hmAlertInfo:info];//提示信息
        }

    }];
    
    
    blockfinally();
    
    
    
}
















//-(void)checkloginIOS:(NSString *)company andUserName:(NSString *)username andPassword:(NSString *)password{
//    
//    NSString *urlStr=[[NSString alloc] initWithFormat:@"%@%@/%@/%@/%@",[HTFrameNet hmGetServerUrl],@"srvlogin/CheckLoginGet",company,username,password];
//    NSURL *url = [NSURL URLWithString:urlStr];
//    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
//    
//    [theRequest setHTTPMethod:@"GET"];
//    NSError *error = nil;
//    NSData *data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:&error];
//    NSString *resultstr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSLog(@"%@",resultstr);
//
//}


@end
